package com.lanou3g.musicenjoy.adapter;

/**
 * Created by dllo on 15/11/5.
 */
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.lanou3g.musicenjoy.R;
import com.lanou3g.musicenjoy.entity.MenuOne;


import java.util.ArrayList;
import java.util.List;


public class MenuItemAdapter extends BaseAdapter{
    private List<MenuOne.ContentEntity> datas;
    private Context mContext;

    public MenuItemAdapter(Context c){
        mContext=c;
    }
    public void initData(List<MenuOne.ContentEntity> datas){
        if (this.datas==null){
            this.datas=new ArrayList<MenuOne.ContentEntity>();
        }else{
            this.datas.clear();
        }
        this.datas=datas;
        notifyDataSetChanged();

    }
    @Override
    public int getCount() {
        return datas!=null&&datas.size()>0?datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return datas!=null&&datas.size()>0?datas.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.fragment_music_item,null);
            holder=new ViewHolder();
            holder.view= (TextView) convertView.findViewById(R.id.itemTextView);
            holder.textView= (TextView) convertView.findViewById(R.id.musicTextView);
            holder.num= (TextView) convertView.findViewById(R.id.num);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        MenuOne.ContentEntity entity= (MenuOne.ContentEntity) getItem(position);
        holder.view.setText(entity.getTitle());
        holder.textView.setText(entity.getAuthor());
        holder.num.setText(position+1+".");

        return convertView;
    }
    private class ViewHolder{
        private TextView textView;
        private TextView view;
        private TextView num;

    }
}

